home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 October / Chip Ekim 2003.iso / prog / code / contr / setup.exe / Disk1 / data1.cab / Paypal_En / Configuration / Commands / Edit PayPal Add to Cart.js < prev    next >
Encoding:
JavaScript  |  2003-07-18  |  14.1 KB  |  375 lines

  1. /*-----------------------------------------------------------------------------
  2. -    File Name:
  3. -        Edit PayPal Add to Cart.js
  4. -
  5. -    Description:
  6. -        Functions for PayPal Add to Cart Advanced Mode.
  7. -
  8. -    This file contains proprietary and confidential information from WebAssist.com
  9. -    corporation.  Any unauthorized reuse, reproduction, or modification without
  10. -    the prior written consent of WebAssist.com is strictly prohibited.
  11. -
  12. -    Copyright 2003 WebAssist.com Corporation.  All rights reserved.
  13. ------------------------------------------------------------------------------*/
  14. var CURRENTPAGE = 0;
  15.  
  16. var theOrig = "";
  17. var updateVersion = false;
  18.  
  19. function commandButtons()     {
  20.   return new Array();
  21. }
  22.  
  23. function displayHelp()     {
  24.   var thePageNum = CURRENTPAGE;
  25.   var anchorLink = "";
  26.   switch (thePageNum)
  27.   {
  28.     case 1:
  29.       break;
  30.       
  31.     case 2:
  32.       anchorLink = "custom_logo";
  33.       break;
  34.       
  35.     case 3:
  36.       anchorLink = "spending_limit";
  37.       break;
  38.       
  39.     default:
  40.       break;
  41.   }
  42.   
  43.   displayContextHelp(anchorLink);
  44. }
  45.  
  46. /* Initialize the UI.  First thing that's called on the body load event. */
  47. function initializeUI()     {
  48.   MM.setBusyCursor();
  49.   if (navigator.platform.toLowerCase().indexOf("mac") >= 0)     {
  50.     document.background.document.tabBgWin.src = "../Shared/PayPal/images/AdvancedBG_Mac.gif";
  51.     document.Tab0.document.tabBG.src = "../Shared/PayPal/images/tabBg_Mac.gif";
  52.     document.Tab1.document.tabBG.src = "../Shared/PayPal/images/longTabBg_Mac.gif";
  53.     document.Tab2.document.tabBG.src = "../Shared/PayPal/images/longTabBg_Mac.gif";
  54.     
  55.     document.background.style = "top:23px;";
  56.     
  57.     document.cancel.style = "position:absolute; width:70px; height:20px; z-index:94; left: 310px; top: 373px; visibility: visible";
  58.     document.cancel.document.btnCancel.style = "width:63; height:20; font-family:'Lucidia Grande'; font-size: 13px";
  59.     
  60.     document.OK.style = "position:absolute; width:70px; height:20px; z-index:94; left: 380px; top: 373px; visibility: visible";
  61.     document.OK.document.btnOK.style = "width:63; height:20; font-family:'Lucidia Grande'; font-size: 13px";
  62.     
  63.     document.help.style = "position:absolute; width:70px; height:20px; z-index:94; left: 240px; top: 373px; visibility: visible";
  64.     document.help.document.btnHelp.style = "width:63; height:20; font-family:'Lucidia Grande'; font-size: 13px";
  65.   
  66.     document.walogo.top = 375;
  67.     document.pplogo.top = 376;
  68.     }
  69.   document.OK.visibility = "visible";
  70.   document.cancel.visibility = "visible";
  71.   document.help.visibility = "visible";
  72.   document.background.visibility = "visible";
  73.   document.Tab0.visibility = "visible";
  74.   document.Tab1.visibility = "visible";
  75.   document.Tab2.visibility = "visible";
  76.   
  77.   // Get values from the inspected node and populate our UI accordingly
  78.   var theDOM = dw.getDocumentDOM();
  79.   var theSelection = theDOM.getSelectedNode();
  80.   theOrig = unescape(theSelection.orig);
  81.   if (getTagType(theOrig).toLowerCase() == "a")  {
  82.     updateVersion = true;
  83.     theOrig = unescape(theSelection.orig.replace(/\%2B/ig," "));
  84.     var theImg = theOrig.match(/<img\s.*src=(['"])([^'"]*)\1/)[2];
  85.     theOrig = theOrig.match(/(['"])[^'"]*https?:\/\/www\.paypal\.com\/cart\/([^'"]*)\1/i)[2];
  86.     theOrig = "cmd=_cart&"+theOrig;
  87.     theOrig = '<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"><input type="image" name="submit" src="'+theImg+'" border="0" alt="Make payments with PayPal - it\'s fast, free and secure!">\r\n<input type="hidden" name="' + theOrig.replace(/=/g,'" value="').replace(/\&/g,'">\r\n<input type="hidden" name="') + '">\r\n</form>';
  88.   }
  89.   else  {
  90.     while (theSelection.tagName!="FORM" && theSelection.parentNode && theSelection.PPwholeForm!="true")  {
  91.       theSelection = theSelection.parentNode;
  92.     }
  93.     theOrig = theSelection.outerHTML;
  94.   }
  95.   var tempOrig = theOrig;
  96.   var firstInput = findOpenTag(tempOrig,"input");
  97.   while (firstInput != "")
  98.   {
  99.     var inputName = getTagProp(firstInput,"input","name");
  100.     var theVal = getTagProp(firstInput,"input","value");
  101.     switch (inputName.toLowerCase())
  102.     {
  103.       case "business":
  104.         if (theVal != "")   
  105.           document.generalWP.document.ppUID.value = theVal;      
  106.         break;
  107.  
  108.       case "item_name":
  109.         if (theVal != "")   
  110.           document.itemWP.document.itemName.value = theVal;      
  111.         break;
  112.  
  113.       case "item_number":
  114.         if (theVal != "")   
  115.           document.itemWP.document.itemID.value = theVal;      
  116.         break;
  117.  
  118.       case "amount":
  119.         if (theVal != "")   
  120.           document.itemWP.document.itemPrice.value = theVal;            
  121.         break;
  122.  
  123.       case "currency_code":
  124.         var theCurrency = document.itemWP.document.itemCurrency;      
  125.         for (var n=0; n<theCurrency.options.length; n++)
  126.         {
  127.             if (theVal == theCurrency.options[n].value)
  128.             {
  129.               theCurrency.selectedIndex = n;
  130.               break;
  131.             }
  132.         }              
  133.         break;                                                                                
  134.                                       
  135.       case "image_url":
  136.         if (isValidURL(theVal))   
  137.           document.generalWP.document.ppLogo.value = theVal;            
  138.         break;
  139.  
  140.       case "return":
  141.         if (isValidURL(theVal))   
  142.           document.generalWP.document.successURL.value = theVal;
  143.         break;
  144.         
  145.       case "cancel_return":
  146.         if (isValidURL(theVal))   
  147.           document.generalWP.document.cancelURL.value = theVal;      
  148.         break;
  149.   
  150.       case "no_shipping":
  151.         if (theVal == "1")
  152.         {
  153.           document.itemWP.document.shippingNo[1].checked = true;
  154.         }
  155.         break;                                                                                
  156.  
  157.       case "no_note":
  158.         if (theVal == "1")
  159.         {
  160.           document.itemWP.document.includeNote[1].checked = true;
  161.         }      
  162.         break;
  163.  
  164.       case "submit":  // button image URL
  165.         var theImg = document.buttonWP.document.acimage;   
  166.         theVal = getTagProp(firstInput,"input","src");
  167.         var myImage = getTranslatedACImage(theVal);
  168.         if (myImage == CUSTOM_AC_IMG)
  169.         {
  170.           myImage = "other";
  171.           document.buttonWP.document.otheracimage.value = theVal;
  172.         }
  173.         
  174.         for (var n=0; n<theImg.length; n++)
  175.         {
  176.             if (myImage == theImg[n].value)
  177.             {
  178.               theImg[n].checked = true;
  179.             }
  180.             else
  181.             {
  182.               theImg[n].checked = false;
  183.             }
  184.         }              
  185.         break;                                                                                
  186.                         
  187.       default:
  188.         break;
  189.     }  
  190.     tempOrig = tempOrig.substring(tempOrig.indexOf(firstInput)+firstInput.length); 
  191.     firstInput = findOpenTag(tempOrig,"input");
  192.     
  193.   }   
  194.     
  195.   enableDisableOtherImage('AC');
  196.  
  197.   // Go to the item details page
  198.   showPageNum(2);
  199.    
  200.   MM.clearBusyCursor();
  201.   
  202.   return true;
  203. }
  204.  
  205. function insertTag()    {
  206.   var myErrors = validateUI();
  207.   if (myErrors == "")
  208.   {
  209.     updateATC(theOrig);
  210.   }
  211.   else
  212.   {
  213.     alert (myErrors);
  214.   }
  215. }
  216.  
  217. function updateATC(formTag)  {
  218.   var theForm = formTag;
  219.   var theBusiness = document.generalWP.document.ppUID.value;
  220.   var theItemName = document.itemWP.document.itemName.value;
  221.   var theItemNumber = document.itemWP.document.itemID.value;
  222.   var theAmount = document.itemWP.document.itemPrice.value;
  223.   var theCurrencyCode = document.itemWP.document.itemCurrency.options[document.itemWP.document.itemCurrency.selectedIndex].value;
  224.   var theImageURL = document.generalWP.document.ppLogo.value;
  225.   var theReturn = document.generalWP.document.successURL.value;
  226.   var theCancel = document.generalWP.document.cancelURL.value
  227.   var theNoShip = (document.itemWP.document.shippingNo[0].checked)?"0":"1";  
  228.   var theNoNote = (document.itemWP.document.includeNote[1].checked)?"1":"0";
  229.   var theButtonImage = document.buttonWP.document.acimage[0].value;
  230.   for (x in document.buttonWP.document.acimage)  {
  231.     if (document.buttonWP.document.acimage[x].checked)
  232.       theButtonImage = document.buttonWP.document.acimage[x].value;
  233.   }
  234.   if (theButtonImage == "other")
  235.     theButtonImage = document.buttonWP.document.otheracimage.value;
  236.   else  
  237.     theButtonImage = "http://images.paypal.com/images/" + theButtonImage;
  238.     
  239.   if (theImageURL == "https://"  || theImageURL == "http://")
  240.     theImageURL = "";
  241.   if (theReturn == "https://"  || theReturn == "http://")
  242.     theReturn = "";
  243.   if (theCancel == "https://"  || theCancel == "http://")
  244.     theCancel = "";
  245.     
  246.   theForm = updateFormInput(theForm,"business",theBusiness);
  247.   theForm = updateFormInput(theForm,"item_name",theItemName);
  248.   theForm = updateFormInput(theForm,"item_number",theItemNumber);
  249.   theForm = updateFormInput(theForm,"amount",theAmount);
  250.   theForm = updateFormInput(theForm,"currency_code",theCurrencyCode);
  251.   theForm = updateFormInput(theForm,"image_url",theImageURL);
  252.   theForm = updateFormInput(theForm,"return",theReturn);
  253.   theForm = updateFormInput(theForm,"cancel_return",theCancel);
  254.   theForm = updateFormInput(theForm,"no_shipping",theNoShip);
  255.   theForm = updateFormInput(theForm,"no_note",theNoNote);
  256.   theForm = updateFormInput(theForm,"bn",BNVersion);
  257.   theForm = updateImage(theForm,theButtonImage);
  258.   var theDOM = dreamweaver.getDocumentDOM();
  259.   var thePage = theDOM.documentElement.outerHTML;
  260.   var theSelection = theDOM.getSelectedNode();
  261.   var theOffsets = new Array();
  262.   if (!updateVersion)  {
  263.     while (theSelection.tagName!="FORM" && theSelection.PPwholeForm!="true")  {
  264.       theSelection = theSelection.parentNode;
  265.     }
  266.   }
  267.   theDOM.setSelectedNode(theSelection);
  268.   theDOM.insertHTML(theForm);
  269.   closeWindow();
  270. }
  271.  
  272. function updateImage(formHTML,image)  {
  273.   var theInput = /<input\s[^<]*type=(['"])image\1/i;
  274.   if (formHTML.search(theInput)>=0)  {
  275.     var theTag = findOpenTag(formHTML.substring(formHTML.search(theInput)),"input");
  276.     formHTML = formHTML.substring(0,formHTML.indexOf(theTag)) + updateTagProp(theTag,"input","src",image) + formHTML.substring(formHTML.indexOf(theTag)+theTag.length);
  277.   }
  278.   else  {
  279.     formHTML = formHTML.substring(0,formHTML.search(/\s*<\/form>/i))+'\r\n<input type="image" name="submit" src="'+image+'" border="0" alt="Make payments with PayPal - it\'s fast, free and secure!">'+formHTML.substring(formHTML.search(/\s*<\/form>/i));
  280.   }
  281.   return formHTML;
  282. }
  283.  
  284. function updateFormInput(formHTML,fieldName,fieldValue)  {
  285.   var theInput = new RegExp('<input\\s[^<]*name=([\'"]?)'+fieldName+'\\1',"i");
  286.   if (formHTML.search(theInput)>=0)  {
  287.     var theTag = findOpenTag(formHTML.substring(formHTML.search(theInput)),"input");
  288.     if (fieldValue!="")
  289.       formHTML = formHTML.substring(0,formHTML.indexOf(theTag)) + updateTagProp(theTag,"input","value",fieldValue) + formHTML.substring(formHTML.indexOf(theTag)+theTag.length);
  290.     else
  291.       formHTML = formHTML.substring(0,formHTML.indexOf(theTag)) + formHTML.substring(formHTML.indexOf(theTag)+theTag.length);
  292.   }
  293.   else  {
  294.     if (fieldValue!="")
  295.       formHTML = formHTML.substring(0,formHTML.search(/\s*<\/form>/i))+'\r\n<input type="hidden" name="'+fieldName+'" value="'+fieldValue+'">'+formHTML.substring(formHTML.search(/\s*<\/form>/i));
  296.   }
  297.   return formHTML;
  298. }
  299.  
  300. function validateUI()    {
  301.   var errMsg = "";
  302.   var accountErrMsg = validatePPUID();
  303.   var nameErrMsg = validateItemName();
  304.   var priceErrMsg = validateItemPrice();
  305.  
  306.   if ( (accountErrMsg != "") || (nameErrMsg != "") || (priceErrMsg != "") )
  307.   {
  308.     errMsg = "The following errors were found:\n\n";
  309.   }
  310.   
  311.   if (accountErrMsg != "")
  312.     errMsg += "PayPal Account " + accountErrMsg;
  313.     
  314.   if (nameErrMsg != "")
  315.     errMsg += "Item Name " + nameErrMsg;
  316.     
  317.   if (priceErrMsg != "")
  318.     errMsg += "Item Price " + priceErrMsg;    
  319.  
  320.   return errMsg;
  321. }
  322.  
  323. /******************************** PAGE FUNCTIONS ********************************/
  324. function Pg0_Load()     {
  325.   document.generalWP.visibility = "visible";
  326.   setTimeout("document.generalWP.document.ppUID.focus()",500);
  327.   return true;
  328. }
  329. function Pg0_unLoad()     {
  330.   document.generalWP.visibility = "hidden";
  331.   document.generalWP.visibility = "visible";
  332.   document.generalWP.visibility = "hidden";
  333.   return true;
  334. }
  335.  
  336. function Pg1_Load()     {
  337.   document.buttonWP.visibility = "visible";
  338.   return true;
  339. }
  340. function Pg1_unLoad()     {
  341.   document.buttonWP.visibility = "hidden";
  342.   document.buttonWP.visibility = "visible";
  343.   document.buttonWP.visibility = "hidden";
  344.   return true;
  345. }
  346.  
  347. function Pg2_Load()     {
  348.   document.itemWP.visibility = "visible";
  349.   setTimeout("document.itemWP.document.itemName.focus()",500);
  350.   return true;
  351. }
  352. function Pg2_unLoad()     {
  353.   document.itemWP.visibility = "hidden";
  354.   document.itemWP.visibility = "visible";
  355.   document.itemWP.visibility = "hidden";
  356.   return true;
  357. }
  358.  
  359. function showPageNum(pageNum)  {
  360.   eval("Pg"+CURRENTPAGE+"_unLoad()");
  361.   if (navigator.platform.toLowerCase().indexOf("mac") >= 0)     {
  362.     eval("document.Tab"+CURRENTPAGE+".document.tabBG.src = document.Tab"+CURRENTPAGE+".document.tabBG.src.substring(0,document.Tab"+CURRENTPAGE+".document.tabBG.src.toLowerCase().lastIndexOf('tabbg'))+'tabBg_Mac.gif'");
  363.   }
  364.   else  {
  365.     eval("document.Tab"+CURRENTPAGE+".document.tabBG.src = document.Tab"+CURRENTPAGE+".document.tabBG.src.substring(0,document.Tab"+CURRENTPAGE+".document.tabBG.src.toLowerCase().lastIndexOf('tabbg'))+'tabBg.gif'");
  366.   }
  367.   CURRENTPAGE = pageNum;
  368.   if (navigator.platform.toLowerCase().indexOf("mac") >= 0)     {
  369.     eval("document.Tab"+CURRENTPAGE+".document.tabBG.src = document.Tab"+CURRENTPAGE+".document.tabBG.src.substring(0,document.Tab"+CURRENTPAGE+".document.tabBG.src.toLowerCase().lastIndexOf('tabbg'))+'tabBgSel_Mac.gif'");
  370.   }
  371.   else  {  
  372.     eval("document.Tab"+CURRENTPAGE+".document.tabBG.src = document.Tab"+CURRENTPAGE+".document.tabBG.src.substring(0,document.Tab"+CURRENTPAGE+".document.tabBG.src.toLowerCase().lastIndexOf('tabbg'))+'tabBgSel.gif'");
  373.   }
  374.   eval("Pg"+CURRENTPAGE+"_Load()");
  375. }